<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <input type="text" id="year1">
    <input type="text" id="year2">
    <button id="btn">提交</button>
    <div>
        封装一个函数，这个函数的作用数，用户输入两个年份，依次打印出这个年份之间所有的闰年，并每4个年份一行进行输出
    </div>
    <div id="res">

    </div>
    <script>
        // var str = '' ;
        // var num = 0 ;
        // for (var i = 1000 ; i <= 2000 ; i ++ ) {
        //     if ( ( i % 4 == 0 && i % 100 != 0 ) || i % 400 == 0 ){
        //         str = str + "&nbsp;&nbsp;" + + i ; 
        //         num ++ ;
        //         if ( num % 4 == 0 ){
        //             str = str + "</br>";
        //         }
        //     }
        // }
        // document.write(str);
        function bissExtile (a) {
            var flag = false ;
            if ( ( a % 4 == 0 && a % 100 != 0) || a % 400 == 0 ) {
                flag = true ;
            }
            return flag;
        }
        function fromTo (year1,year2) {
            var count = 0 ;
            var str = '';
            for ( var i = year1 ; i <= year2 ; i ++ ) {
                if ( bissExtile(i) == true ) {
                    str = str + "&nbsp;&nbsp;" + i ;
                    count ++ ;
                    // console.log(count);
                    if ( count % 4 == 0 ) {
                        str = str + "</br>" ;
                    }
                }
            }
            return str ; 
        }
        var year1 = document.getElementById("year1");
        var year2 = document.getElementById("year2");
        var btn = document.getElementById("btn");
        btn.onclick = function ( ) {
            var a = parseInt(year1.value);
            var b = parseInt(year2.value);
            document.getElementById("res").innerHTML = fromTo(a,b);
        }
    </script>
</body>
</html>